home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_11_05
/
1105048a
< prev
next >
Wrap
Text File
|
1993-03-02
|
2KB
|
83 lines
#include "btree.h"
#undef VERBOSE
#ifdef __TURBOC__
extern unsigned int _stklen = 24576;
#endif
const int NumInts = 1000;
const int NumReps = 1000;
int
compare_ints(const void *a, const void *b)
{
return *(const int *) a - *(const int *) b;
}
int
main()
{
int *arr = new int[NumInts];
int seed;
BinaryTree<int> *inttree;
randomize();
for (int i = 0; i < NumReps; i++) {
int j;
int min = INT_MAX;
int max = INT_MIN;
inttree = new BinaryTree<int>;
cout << i << '\n';
for (j = 0; j < NumInts; j++) {
int x = rand();
if (x < min)
min = x;
if (x > max)
max = x;
arr[j] = x;
inttree->Insert(x);
if (inttree->CheckInvariant())
cout << "Problems\n";
}
if (min != *inttree->Min() ||
max != *inttree->Max())
cout << "Min/max problems\n";
for (j = 0; j < NumInts; j++) {
BinaryTreeIter<int> q(*inttree, arr[j]);
if (*q.Contents() != arr[j])
cout << "Serious problem\n";
}
BinaryTreeIter<int> *inorder = new BinaryTreeIter<int>(*inttree);
inorder->Min();
if (min != *inorder->Contents())
cout << "Problems in inorder initialization\n";
j = 0;
qsort(arr, NumInts, sizeof(int), compare_ints);
while (inorder->Contents()) {
inorder->Succ();
int *next = inorder->Contents();
if (next && (*next < min || *next != arr[++j]))
cout << "Problems in inorder traversal\n";
if (next)
min = *next;
}
for (j = 0; j < NumInts; j++) {
inttree->DeleteItem(arr[j]);
if (inttree->CheckInvariant())
cout << "Problems deleting\n";
BinaryTreeIter<int> q(*inttree, arr[j]);
if (q.Contents() && arr[j+1] != arr[j])
cout << "Problems deleting II\n";
}
delete inttree;
}
return 0;
}